<template>
  <el-dialog title="用户管理" :visible.sync="dialogFormVisible" width="480px">
    <el-form :model="form">
      <el-form-item label="姓名" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" :label-width="formLabelWidth">
        <el-input v-model="form.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="邮件" :label-width="formLabelWidth">
        <el-input v-model="form.email" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="手机号码" :label-width="formLabelWidth">
        <el-input v-model="form.mobile" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="性别" :label-width="formLabelWidth">
        <el-radio-group v-model="form.gender">
          <el-radio :label="1">男</el-radio>
          <el-radio :label="0">女</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="onOk">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ModalForm',
  props: {
    modalForm: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      dialogFormVisible: false,
      formLabelWidth: '120px',
      form: {
        id: '',
        name: '',
        password: '',
        email: '',
        mobile: '',
        gender: ''
      }
    }
  },
  methods: {
    open () {
      this.dialogFormVisible = true
    },
    onOk () {
      this.dialogFormVisible = false
      this.$emit('save', this.form)
    }
  },
  watch: {
    modalForm (val) {
      this.form = { ...val }
    }
  }
}
</script>
